<?php

class Router_Route
{

    private $pattern;
    
	private $module;
    
	private $controller;
    
	private $action;
    
	private $preciseMatch;

    public function __construct($options = array())
    {
        $classVars = get_class_vars(__CLASS__);

        foreach ($classVars as $k => $v)
        {
            if (isset($options[$k]))
            {
                $this->$k = $options[$k];
            }
        }

    }

    public function isMatch()
    {
        $this->convertPattern();

        $urlPostfix = Router_Abstract::getUrlPostfix();
		
        return preg_match($this->pattern, $urlPostfix);

    }

    private function convertPattern()
    {
		$this->pattern = trim($this->pattern,'/');
		
		$this->pattern = str_replace('/', '\/', $this->pattern);
		
        $this->pattern = str_replace(':string', '[a-zA-Z0-9' . URL_CHARS . ']+', $this->pattern);

        $this->pattern = str_replace(':int', '\d+', $this->pattern);

        if (!$this->preciseMatch)
        {
            $this->pattern = $this->pattern . '[a-zA-Z0-9 ' . URL_CHARS . ']+';
        }
		
		$this->pattern = '/^' .$this->pattern . '$/';
    }

    public function getPattern()
    {
        return $this->pattern;

    }

    public function setPattern($pattern)
    {
        $this->pattern = $pattern;

    }

    public function getModule()
    {
        return $this->module;

    }

    public function setModule($module)
    {
        $this->module = $module;

    }

    public function getController()
    {
        return $this->controller;

    }

    public function setController($controller)
    {
        $this->controller = $controller;

    }

    public function getAction()
    {
        return $this->action;

    }

    public function setAction($action)
    {
        $this->action = $action;

    }

    public function getPreciseMatch()
    {
        return $this->preciseMatch;

    }

    public function setPreciseMatch($preciseMatch)
    {
        $this->preciseMatch = $preciseMatch;

    }

}